import request from '@/utils/request'

const api = {
  CPUInfo: '/sys/cpuinfo',
  memoryInfo: '/sys/memoryinfo',
  javaInfo: '/sys/javainfo',
  userList: '/sys/user/list',
  RoleSelectOptions: '/sys/role/roleselectoptions',
  userAdd: '/sys/user/save',
  deleteUser: '/sys/user/del',
  userEdit: '/sys/user/edit',
  changePwd: '/sys/user/changePwd',
  permissionList: '/sys/permission/list',
  permissionAdd: '/sys/permission/save',
  permissionEdit: '/sys/permission/edit',
  permissionDelete: '/sys/permission/del',
  roleList: '/sys/role/list',
  roleAdd: '/sys/role/add',
  roleEdit: '/sys/role/edit',
  roleDelete: '/sys/role/del',
  AssignedMenuList: '/sys/role/AssignedMenuList',
  EditAssignedMenu: '/sys/role/EditAssignedMenu',
  getAssignedUserList: '/sys/role/AssignedUserList',
  editAssignedUser: '/sys/role/editAssignedUserList'
}

export default api

// 用户管理
/**
 * 获取角色下拉选项
 * @returns {AxiosPromise}
 */
export function getSelectOptions () {
  return request({
    url: api.RoleSelectOptions,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * 获取用户分页数据
 * @param parameter
 * @returns {AxiosPromise}
 */
export function getUserList (parameter) {
  return request({
    url: api.userList,
    method: 'get',
    data: parameter
  })
}

/**
 * 新增用户
 * @param parameter
 * @returns {AxiosPromise}
 */
export function userAdd (parameter) {
  return request({
    url: api.userAdd,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * 编辑用户
 * @param parameter
 * @returns {AxiosPromise}
 */
export function userEdit (parameter) {
  return request({
    url: api.userEdit,
    method: 'put',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * 修改用户密码
 * @param parameter
 * @returns {AxiosPromise}
 */
export function changePwd (parameter) {
  return request({
    url: api.changePwd,
    method: 'put',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * 删除用户
 * @param parameter
 * @returns {AxiosPromise}
 */
export function deleteUser (parameter) {
  return request({
    url: api.deleteUser,
    method: 'delete',
    data: parameter
  })
}

// 资源管理
/**
 * 获取全部资源管理数据
 * @returns {AxiosPromise}
 */
export function permissionList () {
  return request({
    url: api.permissionList,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * 新增资源
 * @param parameter
 * @returns {AxiosPromise}
 */
export function permissionAdd (parameter) {
  return request({
    url: api.permissionAdd,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * 编辑资源
 * @param parameter
 * @returns {AxiosPromise}
 */
export function permissionEdit (parameter) {
  return request({
    url: api.permissionEdit,
    method: 'put',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * 删除资源
 * @param parameter
 * @returns {AxiosPromise}
 */
export function permissionDelete (parameter) {
  return request({
    url: api.permissionDelete,
    method: 'delete',
    data: parameter
  })
}

/**
 * 获取角色分页数据
 * @param parameter
 * @returns {AxiosPromise}
 */
export function getRoleList (parameter) {
  return request({
    url: api.roleList,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * 根据角色ID获取已分配的资源ID
 * @param parameter id
 * @returns {AxiosPromise}
 */
export function getAssignedMenuList (parameter) {
  return request({
    url: api.AssignedMenuList,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * 更新分配资源
 * @param parameter
 * @returns {AxiosPromise}
 */
export function updataRoleAssignedMenu (parameter) {
  return request({
    url: api.EditAssignedMenu,
    method: 'put',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * 获取已分配给当前角色的用户列表
 * @returns {AxiosPromise}
 */
export function getAssignedUserList (parameter) {
  return request({
    url: api.getAssignedUserList,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * 更新当前角色已分配用户
 * @param parameter
 * @returns {AxiosPromise}
 */
export function editAssignedUser (parameter) {
  return request({
    url: api.editAssignedUser,
    method: 'put',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * 新增角色
 * @param parameter
 * @returns {AxiosPromise}
 */
export function roleAdd (parameter) {
  return request({
    url: api.roleAdd,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}
/**
 * 编辑角色
 * @param parameter
 * @returns {AxiosPromise}
 */
export function roleEdit (parameter) {
  return request({
    url: api.roleEdit,
    method: 'put',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * 删除角色
 * @param parameter
 * @returns {AxiosPromise}
 */
export function roleDelete (parameter) {
  return request({
    url: api.roleDelete,
    method: 'delete',
    params: parameter
    // data: parameter
  })
}

// 系统监控
export function getCPUInfo () {
  return request({
    url: api.CPUInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function memoryInfo () {
  return request({
    url: api.memoryInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function getJavaInfo () {
  return request({
    url: api.javaInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}
